﻿<UserControl x:Class="PokemonBattleOnline.PBO.Lobby.Login"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	         xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
             xmlns:pm="clr-namespace:PokemonBattleOnline.Game;assembly=PBO.Game"
             xmlns:ui="clr-namespace:PokemonBattleOnline.PBO.Elements"
             xmlns:c="clr-namespace:PokemonBattleOnline.PBO.Converters"
             xmlns:l="clr-namespace:PokemonBattleOnline.PBO.Lobby"
             UseLayoutRounding="True" SnapsToDevicePixels="True">
    <Grid>
        <Border x:Name="login" Margin="25,0" Background="#ffffff" BorderThickness="2" BorderBrush="#80ffffff" MinWidth="180" MaxWidth="300">
            <Grid UseLayoutRounding="True" SnapsToDevicePixels="True">
                <Grid.RowDefinitions>
                    <RowDefinition Height="71"/>
                    <RowDefinition Height="40"/>
                </Grid.RowDefinitions>
                <ContentPresenter x:Name="avatar" MouseDown="avatar_MouseDown" ToolTip="点击选择头像..." Cursor="Hand" ContentTemplate="{x:Static ui:Cartes.Avatar}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="4,2,0,0"/>
                <TextBox Name="name" Foreground="{Binding Text,RelativeSource={RelativeSource Self},Converter={x:Static c:UserColor.C}}" VerticalAlignment="Top" Margin="72,24,5,0" BorderThickness="0,0,0,1" BorderBrush="#6aacf0" FontSize="16" Background="{x:Null}" HorizontalContentAlignment="Center"/>
                <TextBlock Text="{x:Static l:R.Username}" IsHitTestVisible="False" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="70,24,3,0" Foreground="#806aacf0">
                    <TextBlock.Style>
                        <Style TargetType="TextBlock">
                            <Setter Property="Visibility" Value="Collapsed"/>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Text,ElementName=name}" Value="">
                                    <Setter Property="Visibility" Value="Visible"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                </TextBlock>
                <Button Name="button" Grid.Row="1" Content="{x:Static l:R.LoginToServer}" Cursor="Hand" Click="button_Click">
                    <Button.Template>
                        <ControlTemplate TargetType="Button">
                            <Border x:Name="border" Background="#6aacf0">
                                <TextBlock Text="{TemplateBinding Content}" Margin="10,0,0,0" Foreground="White" FontSize="15" FontWeight="Bold" HorizontalAlignment="Left" VerticalAlignment="Center" IsHitTestVisible="False"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter TargetName="border" Property="Background" Value="#003366"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Button.Template>
                </Button>
                <ComboBox Name="servers" Grid.Row="1" Margin="110,0,0,0" IsEditable="True" FontFamily="Microsoft YaHei" BorderThickness="0" Background="Transparent">
                    <ComboBox.Template>
                        <ControlTemplate TargetType="ComboBox">
                            <Grid x:Name="Placement" SnapsToDevicePixels="true">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
                                    <Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=Placement}">
                                        <Border x:Name="DropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
                                            <ScrollViewer x:Name="DropDownScrollViewer">
                                                <Grid RenderOptions.ClearTypeHint="Enabled">
                                                    <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
                                                        <Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=DropDownBorder}" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}"/>
                                                    </Canvas>
                                                    <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                                </Grid>
                                            </ScrollViewer>
                                        </Border>
                                    </Themes:SystemDropShadowChrome>
                                </Popup>
                                <TextBox x:Name="PART_EditableTextBox" Foreground="White" HorizontalContentAlignment="Right" Margin="{TemplateBinding Padding}" VerticalContentAlignment="Center" AllowDrop="True" MinHeight="0" MinWidth="0" ScrollViewer.PanningMode="VerticalFirst" Stylus.IsFlicksEnabled="False">
                                    <TextBox.Template>
                                        <ControlTemplate TargetType="{x:Type TextBox}">
                                            <ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
                                        </ControlTemplate>
                                    </TextBox.Template>
                                </TextBox>
                                <ToggleButton Grid.Column="1" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Width="15" IsTabStop="False" Focusable="False">
                                    <ToggleButton.Template>
                                        <ControlTemplate TargetType="{x:Type ToggleButton}">
                                            <Grid x:Name="bg" Background="Transparent">
                                                <Path x:Name="Arrow" Data="M 0 0 L 3.5 4 L 7 0 Z" Fill="#80ffffff" HorizontalAlignment="Center" Margin="0,1,0,0" VerticalAlignment="Center"/>
                                            </Grid>
                                            <ControlTemplate.Triggers>
                                                <Trigger Property="IsMouseOver" Value="True">
                                                    <Setter TargetName="bg" Property="Background" Value="#20000000"/>
                                                    <Setter TargetName="Arrow" Property="Fill" Value="#ffffff"/>
                                                </Trigger>
                                                <Trigger Property="IsChecked" Value="true">
                                                    <Setter TargetName="bg" Property="Background" Value="#20000000"/>
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </ToggleButton.Template>
                                </ToggleButton>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsKeyboardFocusWithin" Value="true">
                                    <Setter Property="Foreground" Value="Black"/>
                                </Trigger>
                                <Trigger Property="HasItems" Value="false">
                                    <Setter Property="Height" TargetName="DropDownBorder" Value="95"/>
                                </Trigger>
                                <Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false">
                                    <Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/>
                                    <Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/>
                                </Trigger>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="Placement" Property="Background" Value="#20000000"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </ComboBox.Template>
                </ComboBox>
            </Grid>
        </Border>
        <ListBox x:Name="avs" SelectedItem="{Binding ElementName=avatar,Path=Content}" ItemsSource="{x:Static c:IdAvatar.Avatars}" ItemTemplate="{x:Static ui:Cartes.Avatar}" SelectionChanged="avs_SelectionChanged" Visibility="Collapsed" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Background="{x:Null}" BorderThickness="0" BorderBrush="{x:Null}">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel HorizontalAlignment="Center"/>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>
    </Grid>
</UserControl>
